今天進度 : 鳥哥的 Linux 私房菜 -- 第十一章、正規表示法與文件格式化處理
學習 Bash + Grep
例子1 : 使用 grep 正則找相符的字串
test@test:~$ vim demo.txt
# insert
xxxx01
xxxx02
xxxx03
yyyy01
yyyy02
yyyy03
# :wq
test@test:~$ grep ".*03" demo.txt
xxxx03
yyyy03
例子2 : 找尋當下目錄符合規則的檔案
test@test:~$ mkdir demo
test@test:~$ cd demo
test@test:~/demo$ touch {0..10}.txt
test@test:~/demo$ ls
0.txt  10.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt
test@test:~/demo$ ls | grep "[0..5]"
0.txt
10.txt
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
test@test:~/demo$ find | grep "[1|2]"
./1.txt
./10.txt
./2.txt
例子3 : 找尋全電腦目錄符合規則的檔案
test@test:/$ sudo grep '\*' /etc/* 2> /dev/null
[sudo] password for test: 
/etc/adduser.conf:#NAME_REGEX="^[a-z][-a-z0-9_]*\$"
/etc/bash.bashrc:#xterm*|rxvt*)
/etc/bash.bashrc:#*)
/etc/bash.bashrc:    case " $(groups) " in *\ admin\ *|*\ sudo\ *)
/etc/crontab:# *  *  *  *  * user-name command to be executed
/etc/crontab:17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
/etc/crontab:25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
/etc/crontab:47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
/etc/crontab:52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )